package com.example.demo.solon.controller;

import com.example.demo.solon.client.DemoClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import org.noear.nami.annotation.NamiClient;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Param;
import org.noear.solon.net.http.HttpUtils;

/**
 * @author airhead
 */
@Api("Demo")
@Controller
@Mapping
public class DemoController {
  @NamiClient private DemoClient demoClient;

  @ApiOperation("hello")
  @Mapping("/hello")
  public String hello(@Param(defaultValue = "world") String name) {
    try {
      return HttpUtils.http("demo-cloud-service01", "/hello").data("name", name).get();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  @ApiOperation("hello2")
  @Mapping("/hello2")
  public String hello2(@Param(defaultValue = "world") String name) {
    return demoClient.hello(name);
  }
}
